package com.itheima.d5_tcp2.ZengTcpTest;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ClassName sserver
 * @Author 16799
 * @Date 2025/9/26 18:59
 * @Version 1.0
 * @Description TODO
 **/
public class server {
    public static void main(String[] args) throws Exception {
        System.out.println("--------------服务端启动-----------");
        ServerSocket serverSocket = new ServerSocket(8877);

        Socket socket = serverSocket.accept();
        InputStream is = socket.getInputStream();
        DataInputStream dis = new DataInputStream(is);

        while (true){
            try {
                String rs = dis.readUTF();
                System.out.println(rs);
            } catch (Exception e) {
                System.out.println(socket.getRemoteSocketAddress() + "离线了");
                dis.close();
                socket.close();
                break;
            }
        }
    }
}
